package com.atyixiang.hosp.Controller;

import com.atyixiang.hosp.Service.HospService;
import com.atyixiang.model.hosp.Hospital;
import com.atyixiang.vo.hosp.HospitalQueryVo;
import com.atyixiang.commom.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/Hosp/hospital")
//跨域的注解
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospService hospService;

    //查询医院列表(条件带分页)
    @ApiOperation(value = "查询医院列表(条件带分页)")
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageModel = hospService.selectHospPage(page,limit,hospitalQueryVo);
        List<Hospital> content = pageModel.getContent();
        long totalElements = pageModel.getTotalElements();

        return Result.ok(pageModel);
    }

    //更新医院上线状态
    @ApiOperation(value = "更新医院上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status) {
        hospService.updateStatus(id,status);
        return Result.ok();
    }

    //医院详情信息
    @ApiOperation(value = "医院详情信息")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(@PathVariable String id) {
        Map<String, Object> map = hospService.getHospById(id);
        return Result.ok(map);
    }
}
